package com.gg.sdk;

import com.alibaba.cloudapi.sdk.client.ApacheHttpClient;
import com.alibaba.cloudapi.sdk.enums.HttpMethod;
import com.alibaba.cloudapi.sdk.enums.ParamPosition;
import com.alibaba.cloudapi.sdk.enums.Scheme;
import com.alibaba.cloudapi.sdk.model.ApiCallback;
import com.alibaba.cloudapi.sdk.model.ApiRequest;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;


public class HttpApiClient extends ApacheHttpClient{
    public final static String HOST = "yzx.market.alicloudapi.com";
    static HttpApiClient instance = new HttpApiClient();
    public static HttpApiClient getInstance(){return instance;}

    public void init(HttpClientBuilderParams httpClientBuilderParams){
        httpClientBuilderParams.setScheme(Scheme.HTTP);
        httpClientBuilderParams.setHost(HOST);
        super.init(httpClientBuilderParams);
    }




    public void send(String mobile , String param , String tpl_id , ApiCallback callback) {
        String path = "/yzx/sendSms";
        ApiRequest request = new ApiRequest(HttpMethod.POST_FORM , path);
        request.addParam("mobile" , mobile , ParamPosition.QUERY , true);
        request.addParam("param" , param , ParamPosition.QUERY , false);
        request.addParam("tpl_id" , tpl_id , ParamPosition.QUERY , true);



        sendAsyncRequest(request , callback);
    }

    public ApiResponse SyncMode(String mobile , String param , String tpl_id) {
        String path = "/yzx/sendSms";
        ApiRequest request = new ApiRequest(HttpMethod.POST_FORM , path);
        request.addParam("mobile" , mobile , ParamPosition.QUERY , true);
        request.addParam("param" , param , ParamPosition.QUERY , false);
        request.addParam("tpl_id" , tpl_id , ParamPosition.QUERY , true);



        return sendSyncRequest(request);
    }

}